﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MiniFox
{
    /// <summary>
    /// 全局唯一标识序列，默认为yyyyMMddHHmmss格式的日期+无符大写GUID组成，长度为46, 例如: "20150201131649DF8B0C56270B482BA1E5643D1D707F81"
    /// 请使用此类型静态方法 NewGUID 创建实例
    /// </summary>
    public sealed class SequenceGUID : Sequence
    {
        Guid _gid;
        /// <summary>
        /// 
        /// </summary>
        private SequenceGUID() : this(SequenceSetting.CreateDefaultSetting())
        {
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="setting"></param>
        public SequenceGUID(SequenceSetting setting) : base(setting)
        {
            _gid = Guid.NewGuid();
        }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public static SequenceGUID NewGUID()
        {
            SequenceGUID seqid = new SequenceGUID();
            return seqid;
        }
        /// <summary>
        /// 
        /// </summary>
        public string GUID
        {
            get { return _gid.ToString("n").ToUpper(); }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return $"{base.ToString()}{GUID}";
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="seq"></param>
        /// <returns></returns>
        public static implicit operator string(SequenceGUID seq)
        {
            if (seq == null)
                return null;

            return seq.ToString();
        }
    }
}
